'use strict'
const config = require('./src/config')
const path = require('path')

const resolve = dir => {
  return path.join(__dirname, dir)
}

const baseUrl = env => {
  if (env === 'development') {
    return config.baseUrl.dev
  } else {
    return config.baseUrl.pro
  }
}
process.env.BASE_URL = './'

const name = 'vue-easyui' // page title
// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
const port = 9527 // dev port

module.exports = {
  publicPath: process.env.BASE_URL,
  outputDir: 'target/classes/META-INF/resources/',
  lintOnSave: process.env.NODE_ENV === 'development',
  assetsDir: 'webjars',
  productionSourceMap: false,
  devServer: {
    port: port,
    open: true,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      // change xxx-api/login => mock/login
      // detail: https://cli.vuejs.org/config/#devserver-proxy
      [process.env.VUE_APP_BASE_API]: {
        target: baseUrl(process.env.NODE_ENV),
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    },
    after: undefined
  },
  configureWebpack: {
    name: name,
    resolve: {
      alias: {
        vue$: 'vue/dist/vue.esm.js', // 'vue/dist/vue.common.js' for webpack 1
        '@': resolve('src'),
        _c: resolve('src/components'),
        _api: resolve('src/api')
      }
    }
  }
}
